﻿using Microsoft.Extensions.DependencyInjection;
using Puppy;
using Puppy.Data;
using Puppy.Domain.Repositories.MemoryDb;
using Puppy.Modularity;
using Puppy.TestApp.Domain;
using System;

namespace Puppy.MemoryDb
{
    public class AbpMemoryDbTestModule : PuppyModule
    {
        public override void ConfigureServices(ServiceCollectionAccessorContext context)
        {
            var connStr = Guid.NewGuid().ToString();

            Configure<DbConnectionOptions>(options =>
            {
                options.ConnectionStrings.Default = connStr;
            });

            context.Services.AddMemoryDbContext<TestAppMemoryDbContext>(options =>
            {
                options.AddDefaultRepositories();
                options.AddRepository<City, CityRepository>();
            });

            Configure<Utf8JsonMemoryDbSerializerOptions>(options =>
            {
                options.JsonSerializerOptions.Converters.Add(new EntityJsonConverter<EntityWithIntPk, int>());
            });
        }
    }
}
